package com.sgcc.isc.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sgcc.isc.domain.SysDistrict;
import com.sgcc.isc.mapper.SysDistrictMapper;
import com.sgcc.isc.service.ISysDistrictService;

/**
 * 部门映射Service业务层处理
 * 
 * @author sgcc
 * @date 2021-03-17
 */
@Service
public class SysDistrictServiceImpl implements ISysDistrictService 
{
    @Autowired
    private SysDistrictMapper sysDistrictMapper;

    /**
     * 查询部门映射
     * 
     * @param districtId 部门映射ID
     * @return 部门映射
     */
    @Override
    public SysDistrict selectSysDistrictById(String districtId)
    {
        return sysDistrictMapper.selectSysDistrictById(districtId);
    }

    /**
     * 查询部门映射列表
     * 
     * @param sysDistrict 部门映射
     * @return 部门映射
     */
    @Override
    public List<SysDistrict> selectSysDistrictList(SysDistrict sysDistrict)
    {
        return sysDistrictMapper.selectSysDistrictList(sysDistrict);
    }

    /**
     * 新增部门映射
     * 
     * @param sysDistrict 部门映射
     * @return 结果
     */
    @Override
    public int insertSysDistrict(SysDistrict sysDistrict)
    {
    	if(null==sysDistrict.getDistrictId()) {
    		String id=UUID.randomUUID().toString().replaceAll("-", "");
    		sysDistrict.setDistrictId(id);
    	}
    	SysDistrict info = sysDistrictMapper.selectSysDistrictById(sysDistrict.getParentId());
    	if(null==info) {
    		sysDistrict.setAncestors(sysDistrict.getParentId()+","+sysDistrict.getDistrictId());
    	}else {
    		info.setAncestors(info.getAncestors()+","+sysDistrict.getDistrictId());
    	}
    	
        return sysDistrictMapper.insertSysDistrict(sysDistrict);
    }

    /**
     * 修改部门映射
     * 
     * @param sysDistrict 部门映射
     * @return 结果
     */
    @Override
    public int updateSysDistrict(SysDistrict sysDistrict)
    {
        return sysDistrictMapper.updateSysDistrict(sysDistrict);
    }

    /**
     * 批量删除部门映射
     * 
     * @param districtIds 需要删除的部门映射ID
     * @return 结果
     */
    @Override
    public int deleteSysDistrictByIds(String[] districtIds)
    {
        return sysDistrictMapper.deleteSysDistrictByIds(districtIds);
    }

    /**
     * 删除部门映射信息
     * 
     * @param districtId 部门映射ID
     * @return 结果
     */
    @Override
    public int deleteSysDistrictById(String districtId)
    {
        return sysDistrictMapper.deleteSysDistrictById(districtId);
    }

	@Override
	public int insertSysDistrictIsc(SysDistrict sysDistrict) {
    	if(null==sysDistrict.getDistrictId()) {
    		String id=UUID.randomUUID().toString().replaceAll("-", "");
    		sysDistrict.setDistrictId(id);
    	}
        return sysDistrictMapper.insertSysDistrict(sysDistrict);  
	}
}
